using System;
using System.Windows.Forms;
using Com.SharpZebra.ExampleWinformApplication.Labels;
using Com.SharpZebra.Printing;
using Com.TheKua.ZebraPrinting.ExampleWinformApplication.Printers;

namespace Com.SharpZebra.ExampleWinformApplication
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            ApplicationPrinter printer = new ApplicationPrinter();
            printerNames.DataSource = printer.InstalledPrinters();
            printerNames.SelectedItem = printer.DefaultZebraPrinter();

        }

        private void borderedLabelPrintButton_Click(object sender, EventArgs e)
        {
            Print(new BorderedLabel(textBox1.Text, "secondline", "9875"));
        }

        private void Print(IZebraCommand command)
        {
            string zebraInstructions = command.ToZebraInstruction();
            string selectedPrinterName = GetSelectedPrinterName();
            new ZebraPrinter(selectedPrinterName).Print(zebraInstructions);
        }

        private string GetSelectedPrinterName()
        {
            return printerNames.SelectedItem as string;
        }

        private void drawingLabelPrintButton_Click(object sender, EventArgs e)
        {
            Print(new DrawingExampleLabel());
        }
    }
}